package com.grm.sys.controller;

import com.grm.common.entity.Result;
import com.grm.common.annotation.HasPerm;
import com.grm.common.annotation.Log;
import com.grm.sys.model.SysDept;
import com.grm.sys.request.dept.SysDeptAddParam;
import com.grm.sys.request.dept.SysDeptUpdateParam;
import com.grm.sys.response.SysDeptResponse;
import com.grm.sys.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/dept")
public class SysDeptController {
    @Autowired
    private SysDeptService sysDeptService;
    @GetMapping("/all/tree")
    public Result tree(){
        List<SysDeptResponse> tree = sysDeptService.tree();
        return Result.success(tree);
    }

    @Log("添加部门")
    @PostMapping("/add")
    @HasPerm("sys:dept:add")
    public Result add(@RequestBody SysDeptAddParam sysDeptAddParam){
        sysDeptService.add(sysDeptAddParam);
        return Result.success();
    }

    @Log("修改部门")
    @PutMapping("/update")
    @HasPerm("sys:dept:update")
    public Result update(@RequestBody SysDeptUpdateParam sysDeptUpdateParam){
        sysDeptService.update(sysDeptUpdateParam);
        return Result.success();
    }

    @Log("删除部门")
    @PostMapping("/delete")
    @HasPerm("sys:dept:delete")
    public Result delete(@RequestBody List<Long> ids){
        sysDeptService.delete(ids);
        return Result.success();
    }
}
